package com.d3works.apps.base.service;

import com.d3works.apps.base.db.Address;
import com.d3works.apps.base.db.Country;
import com.d3works.exception.D3worksException;
import com.d3works.meta.CallMethod;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.tuple.Pair;
import wslite.json.JSONException;

public interface AddressService {

  public boolean check(String wsdlUrl);

  public Map<String, Object> validate(String wsdlUrl, String search);

  public com.qas.web_2005_02.Address select(String wsdlUrl, String moniker);

  public int export(String path) throws IOException;

  public Address createAddress(
      String addressL2,
      String addressL3,
      String addressL4,
      String addressL5,
      String addressL6,
      Country addressL7Country);

  public Address getAddress(
      String addressL2,
      String addressL3,
      String addressL4,
      String addressL5,
      String addressL6,
      Country addressL7Country);

  @CallMethod
  public boolean checkAddressUsed(Long addressId);

  /**
   * Get or update latitude and longitude.
   *
   * @param address
   * @return
   * @throws JSONException
   * @throws D3worksException
   */
  Optional<Pair<BigDecimal, BigDecimal>> getOrUpdateLatLong(Address address)
      throws D3worksException, JSONException;

  /**
   * Update latitude and longitude.
   *
   * @param address
   * @throws D3worksException
   * @throws JSONException
   */
  Optional<Pair<BigDecimal, BigDecimal>> updateLatLong(Address address)
      throws D3worksException, JSONException;

  /**
   * Reset latitude and longitude.
   *
   * @param address
   */
  void resetLatLong(Address address);

  public String computeFullName(Address address);

  /**
   * Used to fill the string field in invoice, sale/purchase order and stock move
   *
   * @param address
   * @return the string field corresponding to the given address.
   */
  String computeAddressStr(Address address);

  /**
   * Auto-completes some fields of the address thanks to the input zip.
   *
   * @param address
   */
  public void autocompleteAddress(Address address);

  public String getZipCode(Address address);
}
